<?php

/** Zend_Controller_Action */
require_once ROOT_PATH . '/library/Soooner/Controller/WebAction.php';
require_once ROOT_PATH . '/library/Soooner/Controller/WebAction.php';

class TController extends Soooner_Web_Controller_Action
{
	private $_areaid;
	private $_modelT;

    public function init()
    {
        /* Initialize action controller here */
        $this->initDzTemplate();
        $this->_modelT = new Model_Tables_T();
    }
    public function indexAction()
    {
        $tb = $this->_getParam('tb');//表名
		$tB = ucfirst($tb);
		$tn = $this->_getParam('tn');//表意义 
		$tp = $this->_getParam('tp');
		$result = $this->_modelT->getFieldsList($tb);
		$pri = "id";
		foreach($result as $r)
		{
			if($r["Key"]=="PRI")
				$pri = $r["Field"];
		}
		//$template = $this->_dzTemplate;
		if($tp)
        	include $this->_dzTemplate->getFile( 't1.html' );
        else
        	include $this->_dzTemplate->getFile( 't.html' );
    }
    public function saveAction()
    {
    	$tb = $this->_getParam('tb');//表名
    	$tn = $this->_getParam('tn');//表意义
    	$tp = $this->_getParam('tp');    	
    	$c = file_get_contents("http://www.ww.com/t/index/tb/$tb/tn/$tn/tp/$tp");
    	$arr = explode("##########################################",$c);
    	//print_r($arr);
    	$base = "f:/app/";
    	if(!file_exists("$base/models/Tables/"))
    		mkdir("$base/models/Tables/",0777,ture);
    	if(!file_exists("$base/views/templates/"))
    		mkdir("$base/views/templates/",0777,ture);
    	if(!file_exists("$base/views/templates/ajax/"))
    		mkdir("$base/views/templates/ajax/",0777,ture);
    	if(!file_exists("$base/controllers/"))
    		mkdir("$base/controllers/",0777,ture);
    	file_put_contents($base.trim($arr[1]), "<?php\n".trim($arr[2]));
    	file_put_contents($base.trim($arr[3]), trim($arr[4]));
    	file_put_contents($base.trim($arr[5]), trim($arr[6]));
    	file_put_contents($base.trim($arr[7]), trim($arr[8]));
    	file_put_contents($base.trim($arr[9]), trim($arr[10]));
    	file_put_contents($base.trim($arr[11]),  "<?php\n".trim($arr[12]));
    	echo "Files created at $base";
    }
}
